import CONSTANT from '@/common/constants.js';
import http from '@/common/http.js';

export default {
  name: 'myClass',
  components: {},
  data () {
    return {
      studentId: '',
      studentName: '',
      siteId: '',
      keyWords: '',
      status: '',
      pageNo: 1,
      content: [],
      content: {}
    }
  },
  mounted () {
    var _this = this
    _this.studentId = window.sessionStorage.getItem('studentId')
    _this.siteId = window.sessionStorage.getItem('siteId')
    _this.goList()
  },
  methods: {
    goList () {
      var _this = this
      http.get(CONSTANT.CLASSLIST + '?studentId=' + _this.studentId + '&siteId=' + _this.siteId + '&keyWords=' + _this.keyWords + '&status=' + _this.status + '&pageNo=' + _this.pageNo, {
      }, (res) => {
        //alert(JSON.stringify(res))
      //console.log(JSON.stringify(res))
        for (var i = 0; i < res.content.length; i++) {
          if (res.content[i].timeable.indexOf('\r\n') > -1) {
            res.content[i].timeable = res.content[i].timeable.split('\r\n')
            console.log(res.content[i])
            console.log(typeof res.content[i].timeable)
          }
        }
        if (res.content.length > 0) {
          if (_this.pageNo == 1) {
            _this.content = res.content
          } else {
            _this.content = _this.content.concat(res.content)
          }
          for (var i = 0;i < _this.content.length;i++) {
            //alert(_this.content[i].isCanRefund+'---'+_this.content[i].isCanRevoke)
            if (_this.content[i].isCanRefund) {
              _this.content[i].refundName = '申请退费'
              _this.content[i].showRefund = true
            } else if (_this.content[i].isCanRevoke) {
              _this.content[i].refundName = '撤销退费'
              _this.content[i].showRefund = true
            } else {
              _this.content[i].showRefund = false
            }
          }
        } else {
          if (_this.pageNo > 1) {
            _this.pageNo--
          }
          alert('没有更多了!')
        }
      })
    },
    lookMore () {
      var _this = this
      _this.pageNo++
      _this.goList()
    },
    comeBack () {
      window.history.go(-1)
    },
    goRefund (applyId,refundName,refundId) {
      if (refundName == '申请退费') {
        this.$router.push({path: '/refund',query:{applyId:applyId}})
      } else {
        http.post(CONSTANT.REFUNDREVOKE, {
          refundId: refundId
        }, (res) => {
          //alert(JSON.stringify(res))
        if (res.code == 200) {
          alert('退费撤销成功！')
          location.reload()
        } else {
          alert(res.errmsg)
        }
      })
      }
    },
    goPayment (id,applyStatus,applyStatusName,reserveNo,totalFees) {//@click="goPayment(contents.id,contents.applyStatus,contents.applyStatusName)"
      if (applyStatus == '1') {
        http.post(CONSTANT.CLAZZVIEW, {
          siteId: this.siteId,
          id: id,
          studentId: this.studentId
        }, (res) => {
          this.content = res
          http.post(CONSTANT.STUDENTVIEW, {
            siteId: this.siteId,
            studentId: this.studentId
          }, (res) => {
            this.studentName = res.name
            http.post(CONSTANT.QUERYBYRESERVENO + '?siteId=' + this.siteId + '&reserveNo=' + reserveNo, {
            }, (res) => {
            var query = {reserveNo:reserveNo,name:this.content.name,totalFees:res.applyFee,area:this.content.area,classNo:this.content.classNo,frontStatusName:this.content.frontStatusName,year:this.content.year,term:this.content.term,spelName:this.content.spelName,degree:this.content.degree,studentName:this.studentName}
            this.$router.push({path: '/payment',query:query})
          })
          })
        })
      }
    }
  }
}
